﻿Imports AugmentLib.Database
Imports System.Configuration.ConfigurationManager
Imports AugmentLib.InputOutput.Encryption
Imports AugmentLib.WebComponent
Partial Class stransview
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Session("StaffId") Is Nothing Then
            Response.Redirect("Default.aspx")
        Else
            lblhidStaffId.Text = Session("StaffId").ToString
            lblhidStaffType.Text = Session("StaffType").ToString
        End If

        If Session("StaffType").ToString = "2" Then
            Response.Redirect("Default.aspx")
        End If


        If Not Page.IsPostBack Then
            If Not Session("Tid").ToString Is Nothing Then
                lblhidTransId.Text = Session("Tid").ToString
                'Me.Session.Remove("Tid")
                LoadTransInfo()
                Dim strCoBroke As String = String.Empty
                If lblhidCoBrokeAgencyName.Text <> String.Empty Then
                    strCoBroke += "Agency Name : " & lblhidCoBrokeAgencyName.Text.Trim & "<br />"
                End If
                If lblhidCoBrokePhone.Text <> String.Empty Then
                    strCoBroke += "Phone : " & lblhidCoBrokePhone.Text.Trim & "<br />"
                End If
                If lblhidCoBrokeMobile.Text <> String.Empty Then
                    strCoBroke += "Mobile : " & lblhidCoBrokeMobile.Text.Trim & "<br />"
                End If
                If lblhidCoBrokeFax.Text <> String.Empty Then
                    strCoBroke += "Fax : " & lblhidCoBrokeFax.Text.Trim & "<br />"
                End If
                If lblhidCoBrokeEmail.Text <> String.Empty Then
                    strCoBroke += "Email : " & lblhidCoBrokeEmail.Text.Trim & "<br />"
                End If
                lblCoBroke.Attributes.Add("onmouseover", "return overlib('" & strCoBroke & "',ABOVE);")
            Else
                Response.Redirect("TransList.aspx")
            End If
        End If
    End Sub

    Private Sub LoadTransInfo()
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        objDB.OpenConnection()

        objDB.dbVariable.SQLString = "SELECT t.TransactionId, t.PropertyId, t.OpenFileRef, t.CloseFileRef, " & _
                                "p.UnitNumber + ', ' + r.Road + ', ' + o.Location + ', ' + s.State + ', ' + y.Country as 'Address', t.InvoiceNumber, " & _
                                "j.Project, t.ListerId, t.TransactorId, L.Name as Lister, L.Initial as ListerInitial, t.ListDate, t.VendorType, t.VendorName1, t.VendorName2, " & _
                                "t.VendorName3, t.VendorCompany, t.VendorNRIC1, t.VendorNRIC2, t.VendorNRIC3, a.Name as Transactor, a.Initial as TransactorInitial, " & _
                                "t.VendorCompanyNo, t.VendorAddress, t.VendorPhone, t.VendorMobile, t.VendorFax, t.VendorContactPerson, " & _
                                "t.VendorEmail, t.VendorReferral, t.VendorReferralName, t.VendorReferralNRIC, t.TransactDate, " & _
                                "t.VendorReferralContact, t.VendorReferralStatus, t.VendorReferralAmount, t.VendorReferralAmtSum, " & _
                                "t.AgencyFee, t.GST, t.GSTPaidBy, t.ListingFee, t.VendorSolicitorCompany, t.VendorSolicitorName, " & _
                                "t.VendorSolicitorEmail, t.VendorSolicitorAddress, t.VendorSolicitorPhone, t.VendorSolicitorFax, " & _
                                "t.PurchaserType, t.PurchaserName1, t.PurchaserName2, t.PurchaserName3, t.PurchaserCompany, " & _
                                "t.PurchaserNRIC1, t.PurchaserNRIC2, t.PurchaserNRIC3, t.PurchaserCompanyNo, t.PurchaserAddress, " & _
                                "PurchaserPhone, t.PurchaserMobile, t.PurchaserFax, t.PurchaserEmail, t.PurchaserReferral, " & _
                                "t.PurchaserReferralName, t.PurchaserReferralNRIC, t.PurchaserReferralContact, t.Status, " & _
                                "t.PurchaserReferralStatus, t.PurchaserReferralAmount, t.PurchaserReferralAmtSum, t.PurchaserContactPerson, " & _
                                "t.DisbursementFee, t.PurchaserSolicitorCompany, t.PurchaserSolicitorName, t.PurchaserSolicitorEmail, " & _
                                "t.PurchaserSolicitorAddress, t.PurchaserSolicitorPhone, t.PurchaserSolicitorFax, t.CoBroke, " & _
                                "t.CoBrokeId, c.Name as CoBrokeName, c.AgencyName as CoBrokeAgencyName, c.Phone as CoBrokePhone, " & _
                                "c.Mobile as CobrokeMobile, c.Fax as CobrokeFax, c.Email as cobrokeEmail, t.TransListType, " & _
                                "t.TransactedPrice, t.Deposit, t.PaymentType, t.PaymentDate, t.Requisition, t.TotalAgencyFee, " & _
                                "t.ListerAmt, t.ReferralAmt, t.GovAmt, t.GrossAmount, P.SListerId, t.SignDate, t.SignRemark, t.SignComplete, " & _
                                "t.SignCompleteDate, SC.Name as SignCompleteBy, SC.Initial as SignCompleteByInitial, t.SNPDate, t.CollectDate, t.CollectAmt, T.CollectComplete, " & _
                                "t.CollectRemark, CC.Name as CollectCompleteBy, CC.Initial as CollectCompleteByInitial, t.CollectCompleteDate, t.UndoDate, t.UndoRemark, t.UndoAmt, UB.Name as UndoBy, UB.Initial as UndoByInitial " & _
                                "FROM AW_SaleTransaction t LEFT JOIN AW_Staff L on t.ListerId = L.StaffId LEFT JOIN AW_Staff a on t.TransactorId = a.StaffId " & _
                                "LEFT JOIN AW_CoBroke c on t.CoBrokeId = c.CoBrokeId LEFT OUTER JOIN AW_Property p ON p.PropertyId = t.PropertyId " & _
                                "LEFT OUTER JOIN AW_Road r ON p.RoadId = r.RoadId LEFT OUTER JOIN AW_Location o ON r.LocationId = o.LocationId " & _
                                "LEFT OUTER JOIN AW_State s ON o.StateId = s.StateId LEFT OUTER JOIN AW_Country y ON s.CountryId = y.CountryId " & _
                                "LEFT OUTER JOIN AW_Project j ON p.ProjectId = j.ProjectId LEFT OUTER JOIN AW_Staff SC ON t.SignCompleteBy = SC.StaffId " & _
                                "LEFT OUTER JOIN AW_Staff CC ON t.CollectCompleteBy = CC.StaffId LEFT OUTER JOIN AW_Staff UB ON t.UndoBy = UB.StaffId " & _
                                "WHERE TransactionID=@TransId"
        objDB.AddParameter("TransId", Data.SqlDbType.UniqueIdentifier, New Guid(lblhidTransId.Text.Trim))
        objDB.FillData(TempDT, "AW_RentTransaction", Database.SQLCommandType.NormalString)

        objDB.CloseConnection()

        For Each ReadRow As Data.DataRow In TempDT.Rows
            lblhidPropertyId.Text = ReadRow.Item("PropertyId").ToString
            Select Case ReadRow.Item("Status").ToString
                Case "0"
                    lblCurrentStatus.Text = "NEW"
                Case "1"
                    lblCurrentStatus.Text = "PENDING SIGNING"
                Case "2"
                    lblCurrentStatus.Text = "PENDING COLLECTION"
                Case "3"
                    If ReadRow.Item("UndoDate").ToString = "" Then
                        lblCurrentStatus.Text = "COMPLETED"
                    Else
                        lblCurrentStatus.Text = "COMPLETED (ABORTED)"
                    End If
                Case "4"
                    lblCurrentStatus.Text = "RELISTED"
                Case "5"
                    lblCurrentStatus.Text = "RENEWED"
            End Select
            Select Case ReadRow.Item("TransListType").ToString
                Case "1"
                    lblTransact.Text = "SR"
                Case "2"
                    lblTransact.Text = "SC"
                Case "3"
                    lblTransact.Text = "SL"
                Case "4"
                    lblTransact.Text = "SI"
            End Select
            lblOpenFileNum.Text = ReadRow.Item("OpenFileRef").ToString
            If ReadRow.Item("InvoiceNumber").ToString = "" Then
                trInvoiceNum.Visible = False
            Else
                lblInvoiceNum.Text = ReadRow.Item("InvoiceNumber").ToString
                trInvoiceNum.Visible = True
            End If
            If ReadRow.Item("CloseFileRef").ToString = "" Then
                trCloseFileNum.Visible = False
            Else
                lblCloseFileNum.Text = ReadRow.Item("CloseFileRef").ToString
                trCloseFileNum.Visible = True
            End If
            'lblListBy.Text = ReadRow.Item("Lister").ToString
            lblListBy.Text = ReadRow.Item("ListerInitial").ToString
            'lblTransactBy.Text = ReadRow.Item("Transactor").ToString
            lblTransactBy.Text = ReadRow.Item("TransactorInitial").ToString
            If ReadRow.Item("Project").ToString = "" Then
                trProjecName.Visible = False
            Else
                lblProjectName.Text = ReadRow.Item("Project").ToString
                trProjecName.Visible = True
            End If
            lblPremise.Text = ReadRow.Item("Address").ToString

            If ReadRow.Item("ListDate").ToString <> "" Then
                lblListDate.Text = Format(ReadRow.Item("ListDate"), "dd-MMM-yyyy")
            End If

            lblTransactDate.Text = Format(ReadRow.Item("TransactDate"), "dd-MMM-yyyy")
            lblTransactedPrice.Text = String.Format("{0:#,##0.00}", ReadRow.Item("TransactedPrice"))
            Select Case ReadRow.Item("PaymentType").ToString
                Case "1"
                    lblModeofPayment.Text = "CASH"
                Case "2"
                    lblModeofPayment.Text = "CHEQUE"
                Case "3"
                    lblModeofPayment.Text = "TRANSFER"
                Case Else
                    lblModeofPayment.Text = ""
            End Select
            lblRequisition.Text = ReadRow.Item("Requisition").ToString
            lblCoBroke.Text = ReadRow.Item("CoBrokeName").ToString
            lblhidCoBrokeId.Text = ReadRow.Item("CoBrokeId").ToString
            lblhidCoBrokeAgencyName.Text = ReadRow.Item("CoBrokeAgencyName").ToString
            lblhidCoBrokePhone.Text = ReadRow.Item("CoBrokePhone").ToString
            lblhidCoBrokeMobile.Text = ReadRow.Item("CobrokeMobile").ToString
            lblhidCoBrokeFax.Text = ReadRow.Item("CobrokeFax").ToString
            lblhidCoBrokeEmail.Text = ReadRow.Item("cobrokeEmail").ToString
            If ReadRow.Item("VendorName1").ToString = "" Then
                trVName1.Visible = False
            Else
                trVName1.Visible = True
                lblName1.Text = ReadRow.Item("VendorName1").ToString
            End If
            If ReadRow.Item("VendorName2").ToString = "" Then
                trVName2.Visible = False
            Else
                trVName2.Visible = True
                lblName2.Text = ReadRow.Item("VendorName2").ToString
            End If
            If ReadRow.Item("VendorName3").ToString = "" Then
                trVName3.Visible = False
            Else
                trVName3.Visible = True
                lblName3.Text = ReadRow.Item("VendorName3").ToString
            End If
            If ReadRow.Item("VendorCompany").ToString = "" Then
                trVCompanyName.Visible = False
            Else
                trVCompanyName.Visible = True
                lblCompanyName.Text = ReadRow.Item("VendorCompany").ToString
            End If
            If ReadRow.Item("VendorNRIC1").ToString = "" Then
                trVNRIC1.Visible = False
            Else
                trVNRIC1.Visible = True
                lblNRIC1.Text = ReadRow.Item("VendorNRIC1").ToString
            End If
            If ReadRow.Item("VendorNRIC2").ToString = "" Then
                trVNRIC2.Visible = False
            Else
                trVNRIC2.Visible = True
                lblNRIC2.Text = ReadRow.Item("VendorNRIC2").ToString
            End If
            If ReadRow.Item("VendorNRIC3").ToString = "" Then
                trVNRIC3.Visible = False
            Else
                trVNRIC3.Visible = True
                lblNRIC3.Text = ReadRow.Item("VendorNRIC3").ToString
            End If
            If ReadRow.Item("VendorCompanyNo").ToString = "" Then
                trVCompanyNo.Visible = False
            Else
                trVCompanyNo.Visible = True
                lblCompanyNo.Text = ReadRow.Item("VendorCompanyNo").ToString
            End If
            lblContacPerson.Text = ReadRow.Item("VendorContactPerson").ToString
            lblMobile.Text = ReadRow.Item("VendorMobile").ToString
            If ReadRow.Item("VendorReferral").ToString = "0" Then
                trVRefer.Visible = False
            Else
                trVRefer.Visible = True
            End If
            If ReadRow.Item("PurchaserName1").ToString = "" Then
                trPName1.Visible = False
            Else
                trPName1.Visible = True
                lblPName1.Text = ReadRow.Item("PurchaserName1").ToString
            End If
            If ReadRow.Item("PurchaserName2").ToString = "" Then
                trPName2.Visible = False
            Else
                trPName2.Visible = True
                lblPName2.Text = ReadRow.Item("PurchaserName2").ToString
            End If
            If ReadRow.Item("PurchaserName3").ToString = "" Then
                trPName3.Visible = False
            Else
                trPName3.Visible = True
                lblPName3.Text = ReadRow.Item("PurchaserName3").ToString
            End If
            If ReadRow.Item("PurchaserCompany").ToString = "" Then
                trPCompanyName.Visible = False
            Else
                trPCompanyName.Visible = True
                lblPCompanyName.Text = ReadRow.Item("PurchaserCompany").ToString
            End If
            If ReadRow.Item("PurchaserNRIC1").ToString = "" Then
                trPNRIC1.Visible = False
            Else
                trPNRIC1.Visible = True
                lblPNRIC1.Text = ReadRow.Item("PurchaserNRIC1").ToString
            End If
            If ReadRow.Item("PurchaserNRIC2").ToString = "" Then
                trPNRIC2.Visible = False
            Else
                trPNRIC2.Visible = True
                lblPNRIC2.Text = ReadRow.Item("PurchaserNRIC2").ToString
            End If
            If ReadRow.Item("PurchaserNRIC3").ToString = "" Then
                trPNRIC3.Visible = False
            Else
                trPNRIC3.Visible = True
                lblPNRIC3.Text = ReadRow.Item("PurchaserNRIC3").ToString
            End If
            If ReadRow.Item("PurchaserCompanyNo").ToString = "" Then
                trPCompanyNo.Visible = False
            Else
                trPCompanyNo.Visible = True
                lblPCompanyNo.Text = ReadRow.Item("PurchaserCompanyNo").ToString
            End If
            lblPContactPerson.Text = ReadRow.Item("PurchaserContactPerson").ToString
            lblPMobile.Text = ReadRow.Item("PurchaserMobile").ToString
            If ReadRow.Item("PurchaserReferral").ToString = "0" Then
                trPRefer.Visible = False
            Else
                trPRefer.Visible = True
            End If
            lblAgencyFee.Text = String.Format("{0:#,##0.00}", ReadRow.Item("TotalAgencyFee"))
            lblLister.Text = String.Format("{0:#,##0.00}", ReadRow.Item("ListerAmt"))
            lblReferral.Text = String.Format("{0:#,##0.00}", ReadRow.Item("ReferralAmt"))
            lblGov.Text = String.Format("{0:#,##0.00}", ReadRow.Item("GovAmt"))
            lblGrossAmount.Text = String.Format("{0:#,##0.00}", ReadRow.Item("GrossAmount"))

            Select Case ReadRow.Item("SignComplete").ToString
                Case "0"
                    lblSignStatus.Text = "PENDING SIGNING"
                Case "1"
                    lblSignStatus.Text = "COMPLETED SIGNING (By " & ReadRow.Item("SignCompleteByInitial").ToString & " on " & Format(ReadRow.Item("SignCompleteDate"), "dd-MMM-yyyy") & ")"
                    'lblSignStatus.Text = "COMPLETED SIGNING (By " & ReadRow.Item("SignCompleteBy").ToString & " on " & Format(ReadRow.Item("SignCompleteDate"), "dd-MMM-yyyy") & ")"
                Case Else
                    lblSignStatus.Text = ""
            End Select
            If ReadRow.Item("SNPDate").ToString = "" Then
                lblSPDate.Text = ""
            Else
                lblSPDate.Text = Format(ReadRow.Item("SNPDate"), "dd-MMM-yyyy")
            End If
            If ReadRow.Item("SignDate").ToString = "" Then
                lblSignDate.Text = ""
            Else
                lblSignDate.Text = Format(ReadRow.Item("SignDate"), "dd-MMM-yyyy")
            End If

            Select Case ReadRow.Item("CollectComplete").ToString
                Case "0"
                    If ReadRow.Item("SignComplete").ToString = "0" Then
                        trCollection.Visible = False
                        trActualCollection.Visible = False
                        trCollectAmt.Visible = False
                    Else
                        trCollection.Visible = True
                        trActualCollection.Visible = True
                        trCollectAmt.Visible = True
                        lblCollectStatus.Text = "PENDING COLLECTION"
                        If ReadRow.Item("CollectDate").ToString = "" Then
                            lblCollectionDate.Text = ""
                        Else
                            lblCollectionDate.Text = Format(ReadRow.Item("CollectDate"), "dd-MMM-yyyy")
                        End If
                        lblAmt.Text = String.Format("{0:#,##0.00}", ReadRow.Item("CollectAmt"))
                    End If
                Case "1"
                    trCollection.Visible = True
                    trActualCollection.Visible = True
                    trCollectAmt.Visible = True
                    'lblCollectStatus.Text = "COMPLETED COLLECTION (By " & ReadRow.Item("CollectCompleteBy").ToString & " on " & Format(ReadRow.Item("CollectCompleteDate"), "dd-MMM-yyyy") & ")"
                    lblCollectStatus.Text = "COMPLETED COLLECTION (By " & ReadRow.Item("CollectCompleteByInitial").ToString & " on " & Format(ReadRow.Item("CollectCompleteDate"), "dd-MMM-yyyy") & ")"
                    If ReadRow.Item("CollectDate").ToString = "" Then
                        lblCollectionDate.Text = ""
                    Else
                        lblCollectionDate.Text = Format(ReadRow.Item("CollectDate"), "dd-MMM-yyyy")
                    End If
                    lblAmt.Text = String.Format("{0:#,##0.00}", ReadRow.Item("CollectAmt"))
                Case Else
                    trCollection.Visible = False
                    trActualCollection.Visible = False
                    trCollectAmt.Visible = False
            End Select
            If ReadRow.Item("UndoDate").ToString = "" Then
                trAbortStatus.Visible = False
                trAbortDAte.Visible = False
                trAbortRemark.Visible = False
                trAbortAmt.Visible = False
            Else
                If ReadRow.Item("SignComplete").ToString = "" Or ReadRow.Item("SignComplete").ToString = "0" Then
                    trSign.Visible = False
                    trSNPDate.Visible = False
                    trActualSignDate.Visible = False
                Else
                    trSign.Visible = True
                    trSNPDate.Visible = True
                    trActualSignDate.Visible = True
                End If
                If ReadRow.Item("CollectComplete").ToString = "" Or ReadRow.Item("CollectComplete").ToString = "0" Then
                    trCollection.Visible = False
                    trActualCollection.Visible = False
                    trCollectAmt.Visible = False
                Else
                    trCollection.Visible = True
                    trActualCollection.Visible = True
                    trCollectAmt.Visible = True
                End If
                trAbortStatus.Visible = True
                trAbortDAte.Visible = True
                trAbortRemark.Visible = True
                trAbortAmt.Visible = True
                'lblAbortStatus.Text = "ABORTED (By " & ReadRow.Item("UndoBy").ToString & " on " & Format(ReadRow.Item("UndoDate"), "dd-MMM-yyyy")
                lblAbortStatus.Text = "ABORTED (By " & ReadRow.Item("UndoByInitial").ToString & " on " & Format(ReadRow.Item("UndoDate"), "dd-MMM-yyyy")
                lblAbortDAte.Text = Format(ReadRow.Item("UndoDate"), "dd-MMM-yyyy")
                lblAbortRemark.Text = ReadRow.Item("UndoRemark").ToString
                lblAbortAmt.Text = String.Format("{0:#,##0.00}", ReadRow.Item("UndoAmt"))
            End If
        Next

    End Sub

    Protected Sub btnBack_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnBack.Click
        Dim strBack As String = Session("Back").ToString
        Dim arr() As String = strBack.Split("ڡ")
        Response.Redirect(arr(0).ToString)
    End Sub
End Class
